//
//  SheetsBoot.swift
//  SwiftUIWidgetDemo
//
//  Created by alanzhangg on 2023/7/14.
//

import SwiftUI

struct SheetsBoot: View {
    
    @State var showSheet: Bool = false
    @State var showSheet_2: Bool = false
    
    var body: some View {
        ZStack{
            
            Color.green
                .ignoresSafeArea()
            
            Button(action: {
                showSheet_2.toggle()
            }, label: {
                Text("Button")
                    .foregroundStyle(.green)
                    .font(.headline)
                    .padding()
                    .background(
                        RoundedRectangle(cornerRadius: 10)
                            .fill(.white)
                    )
            })
            
            
            .sheet(isPresented: $showSheet, content: {
                //不要逻辑判断
                SecondScreen()
            })
            .fullScreenCover(isPresented: $showSheet_2, content: {
                SecondScreen()
            })
            
        }
    }
}

struct SecondScreen: View {
    
    @Environment(\.dismiss) private var dismiss
    
    var body: some View {
        ZStack{
            
            Color.red
                .ignoresSafeArea()
            
            Button(action: {
                dismiss()
            }, label: {
                Text("Button")
                    .foregroundStyle(.green)
                    .font(.headline)
                    .padding()
                    .background(
                        RoundedRectangle(cornerRadius: 10)
                            .fill(.white)
                    )
            })
            
        }
    }
}

#Preview {
    SheetsBoot()
}
